"""
依赖注入单元测试专用配置

提供DI测试所需的基础配置和fixture。
"""

import pytest
import sys
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent.parent.parent
sys.path.insert(0, str(project_root))


def pytest_configure(config):
    """pytest配置"""
    # 设置测试标记
    config.addinivalue_line("markers", "unit: 单元测试")
    config.addinivalue_line("markers", "di: 依赖注入测试")


@pytest.fixture(autouse=True)
def reset_injector():
    """自动重置注入器"""
    try:
        from src.core.di import Injector
        Injector.reset()
        yield
        Injector.reset()
    except ImportError:
        yield


@pytest.fixture
def container():
    """容器fixture"""
    from src.core.di import Container
    return Container()


@pytest.fixture
def injector():
    """注入器fixture"""
    from src.core.di import Injector
    Injector.reset()
    return Injector()
